<template>
  <div class="fullMain">
    <div style="position: fixed; width: 100%; z-index: 999">
      <x-header
        class="custumHeader"
        :left-options="{ backText: '', showBack: false }"
      >
        <a style="color: #d9d9d9; font-size: 17px">{{ groupNameAbbreviate }}</a>
        <a
          slot="right"
          style="color: white; font-size: 17px"
          @click="saveModify"
          >Save</a
        >
      </x-header>
    </div>
    <!--插入验证提示框-->
    <div v-transfer-dom>
      <alert v-model="isShowAlert"> {{ alertText }}</alert>
    </div>
    <div style="height: 60px" />
    <div v-transfer-dom>
      <confirm
        v-model="isShowModifyMinLength"
        show-input
        title="汇报的字数限制"
        @on-confirm="onConfirmOfLength"
      >
      </confirm>
    </div>
    <div v-transfer-dom>
      <confirm
        v-model="isShowConfirm"
        title=""
        @on-cancel="onCancel"
        @on-confirm="onConfirm"
      >
        <p style="text-align: center">{{ confirmMessage }}</p>
      </confirm>
    </div>
    <div v-transfer-dom>
      <confirm
        v-model="isShowWeChatNameConfirm"
        show-input
        title="微信群绑定"
        @on-confirm="onWeChatIdConfirm"
      >
      </confirm>
    </div>
    <!-- <div v-transfer-dom>
        <confirm v-model="isShowModifyGroupName"
                 show-input
                 title="请输入新的群名称"
                 @on-confirm="onConfirmNewGroupName">
        </confirm>
      </div> -->
    <div class="mainbBg">
      <div>
        <search
          @on-change="searchResultFun"
          v-model="searchCondition"
          placeholder="请姓名进行快速查找"
          position="absolute"
          auto-scroll-to-top
          top="46px"
          @on-cancel="onCancelSearch"
          @on-submit="searchResultFun"
          ref="search"
        ></search>
        <ul v-show="showSearchResult" class="ul_box">
          <li
            v-for="(item, index) in searchResult"
            :key="index"
            class="list_item"
          >
            <span @click="toMemberDetailPage(item)" class="search_item"
              >&nbsp;{{ item.detail.name }}&nbsp;</span
            >
          </li>
        </ul>
      </div>
      <group style="margin-top: 20px">
        <div class="userList">
          <divider style="margin: 5px; color: #b2b2b2">管理员</divider>
          <div class="manager">
            <div
              class="userInf"
              v-for="(item, index) in groupManagers"
              :key="index"
            >
              <div @click="toMemberDetailPage(item)">
                <img
                  :src="item.detail.avatar"
                  alt=""
                  class="manager_avatar"
                /><br />
                <span
                  style="
                    display: inline-block;
                    font-size: 11px;
                    color: gray;
                    max-width: 50px;
                    max-height: 15px;
                    overflow: hidden;
                  "
                  >{{ item.detail.name }}</span
                >
              </div>
            </div>
          </div>
          <divider style="margin: 5px; color: #b2b2b2">全部成员</divider>
          <div class="limit_height" id="allMembers">
            <div
              class="userInf"
              v-for="(item, index) in groupMembers"
              :key="index"
            >
              <div @click="toMemberDetailPage(item)">
                <img
                  :src="item.detail.avatar"
                  alt=""
                  class="manager_avatar"
                /><br />
                <span
                  style="
                    display: inline-block;
                    font-size: 11px;
                    color: gray;
                    max-width: 50px;
                    max-height: 15px;
                    overflow: hidden;
                  "
                  >{{ item.detail.name }}</span
                >
              </div>
            </div>
          </div>
          <div
            style="padding: 15px 5px 10px 5px; text-align: center; color: grey"
            @click="showMoreMembers"
          >
            {{ memberTips }}
          </div>
        </div>
        <div style="height: 10px" />
      </group>
      <group style="margin-top: 20px">
        <cell
          :title="groupNameTitle"
          :value="this.groupName"
          @click.native="isModifyGroupName"
          is-link
        ></cell>
        <cell
          title="绑定微信群"
          @click.native="bindWeChatGroupId"
          is-link
          :value="this.weChatGroupName"
        >
          <!--          <i class="fa fa-android"></i>-->
        </cell>
        <cell title="群二维码" @click.native="toGroupQRCodePage" is-link>
          <i class="fa fa-qrcode"></i>
        </cell>
        <cell title="群文件" @click.native="toGroupFilePage" is-link>
          <i class="fa fa-folder"></i>
        </cell>
        <cell title="设备资产" @click.native="toGroupDevice" is-link>
          <i class="fa fa-desktop"></i>
        </cell>
        <x-switch
          title="是否对本群成员展示日报"
          :value-map="[false, true]"
          v-model="isShowMyReport"
          @on-change="changePublicSelection"
        ></x-switch>
      </group>
      <group v-if="isGroupAdmin || isGroupOwner" style="margin-top: 20px">
        <cell title="群公告" @click.native="toAnnouncement" is-link></cell>
        <x-switch
          title="加群是否验证"
          :disabled="readonly"
          @on-change="modifyGroupInfo"
          :value-map="[false, true]"
          v-model="needConfirm"
        ></x-switch>
      </group>
      <group v-if="isGroupAdmin || isGroupOwner" style="margin-top: 20px">
        <checker
          v-model="reportType"
          default-item-class="demo1-item"
          selected-item-class="demo1-item-selected"
          radio-required
          style="margin-left: 15px; border-top: #d9d9d9 solid 0.7px"
        >
          <h5
            style="
              margin: 15px 0 15px 15px;
              font-weight: normal;
              color: rgb(191, 191, 191);
              text-align: left;
            "
          >
            每种汇报设置后，请及时点击右上方保存哦
          </h5>
          <checker-item value="日报" @click.native="getGroupSetting('日报')"
            >日报</checker-item
          >
          <checker-item value="周报" @click.native="getGroupSetting('周报')"
            >周报</checker-item
          >
          <checker-item value="月报" @click.native="getGroupSetting('月报')"
            >月报</checker-item
          >
          <checker-item value="年报" @click.native="getGroupSetting('年报')"
            >年报</checker-item
          >
        </checker>
        <div
          v-if="isGroupAdmin || isGroupOwner"
          style="border: green 1px solid; margin-top: -1px"
        >
          <x-switch
            title="是否启用:"
            :disabled="readonly"
            @on-change="modifyGroupInfo"
            :value-map="[false, true]"
            v-model="reportEnable"
          ></x-switch>
          <x-switch
            title="是否提醒同学进行汇报:"
            :disabled="readonly"
            @on-change="modifyGroupInfo"
            v-show="reportType !== '年报'"
            :value-map="[false, true]"
            v-model="needReminder"
          ></x-switch>
          <cell
            title="每时段汇报的最少字数:"
            :value="minLength"
            @click.native="modifyMinLength()"
            is-link
          ></cell>
          <popup-radio
            title="未按时汇报罚款金额:"
            v-model="amountOfPunish"
            v-show="reportType === '日报'"
            :options="amountOfPunishList"
            @on-hide="modifyAmountOfPunish()"
          ></popup-radio>
          <div v-if="needReminder" style="border-top: #35495e 1px solid">
            <popup-radio
              v-show="reportType === '周报'"
              title="何时提醒同学进行汇报-日期:"
              :options="weekRemindDate"
              v-model="sendWriteReminderToMemberDate"
            ></popup-radio>
            <cell
              title="何时提醒同学进行汇报-日期:"
              v-show="reportType === '月报'"
              primary="content"
              :inline-desc="
                '（每月' + tempSendWriteReminderToMemberDate + '号提醒）'
              "
            >
              <range
                v-model="tempSendWriteReminderToMemberDate"
                :min="1"
                :max="28"
                :step="1"
              ></range>
            </cell>
            <datetime
              :readonly="readonly"
              v-show="needReminder"
              @on-change="modifyGroupInfo"
              v-model="sendWriteReminderToMember"
              title="何时提醒同学进行汇报-时间"
              format="HH:mm"
            ></datetime>
          </div>
          <div v-if="needReminder" style="border-top: #35495e 1px solid">
            <popup-radio
              v-show="reportType === '周报'"
              title="何时向我反馈进度-日期:"
              :options="weekRemindDate"
              placeholder="placeholder"
              v-model="sendStatToAdminDate"
            ></popup-radio>
            <cell
              title="何时向我反馈进度-日期:"
              v-show="reportType === '月报'"
              primary="content"
              :inline-desc="'（每月' + tempSendStatToAdminDate + '号提醒）'"
            >
              <range
                v-model="tempSendStatToAdminDate"
                :min="1"
                :max="28"
                :step="1"
              ></range>
            </cell>
            <datetime
              :readonly="readonly"
              @on-change="modifyGroupInfo"
              v-model="sendStatToAdmin"
              title="何时向我反馈进度-时间:"
              format="HH:mm"
            ></datetime>
          </div>

          <!-- 这里没有配套的修改，所以暂时隐藏一下 -->
          <!-- <div style="padding-top: 10px;margin-left: 15px;border-top: solid 1px #D9D9D9;margin-bottom: 25px" v-show="reportType==='月报'">
            <span>请设置月报使用频率：</span>
            <input  v-model="period"
                    placeholder="1" style="width: 20px;"></input>月/次
          </div> -->
          <div style=""></div>
        </div>
      </group>

      <group style="margin-top: 20px">
        <x-button type="warn" @click.native="isSureOfDismissing()"
          >删除并退出</x-button
        >
      </group>
      <div style="border: 20px solid #fff"></div>
    </div>
  </div>
</template>

<script>
import {
  XHeader,
  Cell,
  XSwitch,
  Group,
  Datetime,
  Confirm,
  PopupPicker,
  PopupRadio,
  Checker,
  CheckerItem,
  Divider,
  Search,
  Panel,
  Range,
  TransferDomDirective as TransferDom,
} from "vux";
import { XInput, XButton } from "vux";
import ModifyGroupName from "components/ModifyGroupName/ModifyGroupName.vue";
import { mapState } from "Vuex";
import group from "api/group";
import report_reminder from "api/report_reminder";
import { compareByPinyin } from "utilMethods/sort.js";
import { isInArray } from "utilMethods/traversal.js";

export default {
  name: "G_group_member",
  directives: {
    TransferDom,
  },
  data() {
    return {
      groupNameTitle: "群全称",
      weChatGroupName: "", //绑定机器人管理的微信群号
      memberNumTitle: "群人数",
      alertText: "",
      isShowAlert: false,
      groupId: "",
      groupName: "",
      groupNameAbbreviate: "",
      groupMembers: [],
      groupManagers: [], //群管理员，第一个为群主
      memberNum: "",
      memberTips: "查看更多群成员 ▾ ", //查看更多成员按钮提示
      moreMemberFlag: false,
      allGroupInfo: {}, //存群信息
      isShowModifyGroupName: false,
      isShowMyReport: false, //是否展示我的日报
      isShowModifyMinLength: false, //是否显示字数的修改框
      isShowConfirm: false, //是否显示退群的警告框
      isShowWeChatNameConfirm: false, //绑定微信群号的弹窗
      confirmMessage: "", //confirm的提示信息
      searchCondition: "", //搜索条件
      searchResult: [], //存放搜索的结果
      showSearchResult: false, //控制显示搜索结果

      amountOfPunish: "不罚款",
      amountOfPunishList: ["不罚款", "5元", "10元", "15元", "20元"],
      isShowModifyAmountOfPunish: false,
      needConfirm: false,
      needReminder: false,

      reportEnable: true,
      minLength: 20,
      sendStatToAdmin: "09:00",
      sendStatToAdminDate: "",
      tempSendStatToAdminDate: 0, //由于数据类型问题，暂存接口中的sendStatToAdminDate参数值
      sendWriteReminderToMember: "23:00",
      sendWriteReminderToMemberDate: "",
      tempSendWriteReminderToMemberDate: 0, //由于数据类型问题，暂存接口中的sendWriteReminderToMemberDate参数值
      period: 1, //目前只有月在使用
      reportType: "日报", //选择开放使用的汇报类型
      reportsSetting: [], //本群各种汇报类型设置的汇总

      weekRemindDate: [
        { key: "MON", value: "周一" },
        { key: "TUE", value: "周二" },
        { key: "WED", value: "周三" },
        { key: "THU", value: "周四" },
        { key: "FRI", value: "周五" },
        { key: "SAT", value: "周六" },
        { key: "SUN", value: "周日" },
      ],
      daysOfMonth: 28,
    };
  },
  computed: {
    ...mapState({
      userInfo: (state) => state.user.userInfo,
    }),
    ...mapState(["isGroupOwner", "isGroupAdmin", "groupPresent"]),
    readonly() {
      if (this.isGroupAdmin || this.isGroupOwner) {
        return false;
      } else {
        return true;
      }
    },
  },
  mounted() {
    this.getGroupInfo();
    this.getGroupMembers();
    this.settingReport();
    // this.daysOfMonthFun()
    // this.getGroupSetting('日报')
  },
  watch: {
    // monthPeriod(val){
    //   this.modifyGroupInfo()
    // }
    // tempSendStatToAdminDate (val) {
    //   this.sendStatToAdminDate=val.toString()
    // },
    // tempSendWriteReminderToMemberDate (val) {
    //   this.sendWriteReminderToMemberDate=val.toString()
    // },
    searchCondition(val) {
      this.showSearchResult = !(val === null || val === "");
    },
  },
  components: {
    XHeader,
    XInput,
    PopupPicker,
    PopupRadio,
    ModifyGroupName,
    Cell,
    XSwitch,
    Group,
    Datetime,
    Confirm,
    TransferDom,
    XButton,
    Checker,
    CheckerItem,
    Divider,
    Search,
    Panel,
    Range,
  },
  methods: {
    back() {
      this.$router.go(-1);
    },
    showAlert(alertText) {
      this.isShowAlert = true;
      this.alertText = alertText;
    },
    closeTip() {
      this.isShowAlert = false;
      this.alertText = "";
    },
    toMemberDetailPage(memberSelected) {
      this.$store.commit("stageMemberSelected", memberSelected);
      this.$router.push({ name: "G_group_member_detail" });
    },
    toGroupQRCodePage() {
      this.$router.push({ name: "G_groupQRCode" });
    },
    toGroupFilePage() {
      this.$router.push({
        name: "G_groupFile",
        params: { groupId: this.groupPresent.groupId },
      });
    },
    toGroupDevice() {
      this.$router.push({
        name: "G_group_device",
        params: {
          groupId: this.groupPresent.groupId,
          groupMembers: this.groupMembers,
        },
      });
    },
    toAnnouncement() {
      if (this.isGroupAdmin || this.isGroupOwner) {
        // 880:物联网实验室; 21:嘻嘻
        // if (this.groupPresent.groupId === 880 || this.groupPresent.groupId === 21) {
        //   this.$router.push({name: 'G_group_announcement'});
        // } else {
        //   this.$router.push({name: 'U_send_message'});
        // }
        this.$router.push({ name: "G_group_announcement" });
      } else {
        this.showAlert("您暂无权限发送公告");
        setTimeout(this.closeTip, 3000);
      }
    },
    // plusUser () {
    //   this.isShowPlus = true
    // },
    async getGroupInfo() {
      const result = await group.getGroupInfoByGroupId(
        this.groupPresent.groupId
      );
      if (result.code === 0) {
      } else {
        this.memberNum = result.data.userIdList.length;
        this.allGroupInfo = result.data;
        // this.reportType=this.allGroupInfo.group.detail.usedReportType
        // this.monthPeriod = this.allGroupInfo.group.detail.monthPeriod
        // this.modifyReportType()
        this.isShowMyReport = this.allGroupInfo.open;
        // if (this.allGroupInfo.group.detail.minLength === 0 || this.allGroupInfo.group.detail.minLength === undefined) {
        //   this.minLength = 20
        // } else {
        //   this.minLength = this.allGroupInfo.group.detail.minLength
        // }

        this.needConfirm = this.allGroupInfo.group.detail.needConfirm;
        this.needReminder = this.allGroupInfo.group.detail.needReminder;
        this.weChatGroupName = this.allGroupInfo.group.detail.weChatGroupName;

        if (this.allGroupInfo.group.detail.unfinishedInfoToAdmin === null) {
          this.sendStatToAdmin = "09:00";
        } else {
          this.sendStatToAdmin = this.allGroupInfo.group.detail.unfinishedInfoToAdmin;
        }

        if (
          this.allGroupInfo.group.detail.unfinishedReminderToMember === null
        ) {
          this.sendWriteReminderToMember = "23:00";
        } else {
          this.sendWriteReminderToMember = this.allGroupInfo.group.detail.unfinishedReminderToMember;
        }
        if (this.allGroupInfo.group.detail.fine === 0) {
          this.amountOfPunish = "不罚款";
        } else {
          this.amountOfPunish = this.allGroupInfo.group.detail.fine + "元";
        }
      }
    },
    async getGroupMembers() {
      // rock wang: 这里不要用路由来传参，
      // 因为跳转到群成员个人信息页面后，再跳回来这个页面，就没有这些信息了
      // 还是要传到state里面供全局使用，这样每次从相对距离为1的页面跳转到此页面，就不会白屏了
      // this.groupId = this.$route.params.groupId
      // this.groupName = this.$route.params.groupName
      this.groupId = this.groupPresent.groupId;
      this.groupName = this.groupPresent.detail.groupName;
      this.groupNameAbbreviate = this.groupName.slice(
        this.groupName.lastIndexOf("-") + 1
      );
      if (!this.groupId || !this.groupName) {
        return;
      }
      // 判断是否为群主，并将结果传入state
      this.$store.commit(
        "stageIsGroupOwner",
        this.groupPresent.detail.ownerId === this.userInfo.userId
      );
      const result = await group.getInfoOfMembers({ groupId: this.groupId });
      if (result.code === 0) {
        this.showAlert("群成员获取失败，请稍后再试");
      } else if (result.code === 1) {
        this.groupMembers = result.data;
        // rock wang: 按姓名排序（存在多音字问题）
        // this.groupMembers.sort(compareByPinyin('detail name'))
      }
      const managers = await group.getInfoOfManagers(this.groupId);
      if (result.code === 0) {
        this.showAlert("管理员获取失败");
      } else if (result.code === 1) {
        this.groupManagers = managers.data;
        console.log("群管理员", this.groupManagers);
      }
    },
    isModifyGroupName() {
      if (this.isGroupAdmin || this.isGroupOwner) {
        this.$store.commit(
          "stageGroupNameDividedList",
          this.addressGroupName(this.groupName)
        );
        this.$router.push({ name: "G_modify_group_name" });
      } else {
        this.showAlert("您无操作权限");
      }
    },
    addressGroupName(groupName) {
      let temp = groupName.split("-");
      let groupNameDivided = [];
      const LENGTH_OF_GROUPNAME_LIST = 4;
      if (temp[0] !== this.userInfo.detail.place) {
        groupNameDivided[LENGTH_OF_GROUPNAME_LIST - 1] = temp[0];
        for (let i = 0; i < LENGTH_OF_GROUPNAME_LIST - 1; i++) {
          groupNameDivided[i] = "";
        }
      } else {
        let numOfNullInGroupName = LENGTH_OF_GROUPNAME_LIST - temp.length;
        groupNameDivided[0] = temp[0];
        for (let i = 1; i < LENGTH_OF_GROUPNAME_LIST; i++) {
          if (i <= numOfNullInGroupName) {
            groupNameDivided[i] = "";
          } else {
            groupNameDivided[i] = temp[i - numOfNullInGroupName];
          }
        }
      }
      return groupNameDivided;
    },
    onConfirmNewGroupName(value) {
      this.groupName = value;
      this.modifyGroupInfo();
    },
    changePublicSelection() {
      this.groupId = this.groupPresent.groupId;
      if (this.isShowMyReport !== this.allGroupInfo.open) {
        const result = group.getReportPublic({ groupId: this.groupId });
      }
    },
    modifyMinLength() {
      console.log("我是不是管理者", this.isGroupAdmin, this.isGroupOwner);
      if (this.isGroupAdmin || this.isGroupOwner) {
        this.isShowModifyMinLength = true;
      }
    },
    modifyAmountOfPunish() {
      this.modifyGroupInfo();
    },
    onConfirmOfLength(value) {
      this.minLength = value;
      this.modifyGroupInfo();
    },
    isSureOfDismissing() {
      this.isShowConfirm = true;
      if (!this.isGroupOwner) {
        this.confirmMessage = "删除并退出后，将不再接受此群的信息!";
      } else {
        this.confirmMessage = "群主退出后该群将直接解散，请谨慎选择！";
      }
    },
    onCancel() {
      this.isShowConfirm = false;
      this.isShowWeChatNameConfirm = false;
    },
    onCancelSearch() {
      this.searchResult = [];
    },
    async onConfirm() {
      if (this.isGroupOwner) {
        this.deleteThisGroup();
      } else {
        this.exitGroup();
      }
    },
    onWeChatIdConfirm(val) {
      this.weChatGroupName = val;
      this.saveModify();
      // this.modifyGroupInfo();
    },
    async deleteThisGroup() {
      const result = await group.deleteGroupByGroupId(
        this.groupPresent.groupId
      );
      if (result.code === 1) {
        this.showAlert("已成功解散该群");
        setTimeout(this.back, 1500);
      } else if (result.code === 0) {
        this.showAlert("解散该群失败");
      }
    },
    async exitGroup() {
      const result = await group.postQuitGroup({
        groupId: this.groupPresent.groupId,
      });
      if (result.code === 0) {
        this.showAlert("退出失败，请稍后再试。");
      } else {
        this.showAlert("成功退出");
        setTimeout(this.back(), 1000);
      }
    },

    bindWeChatGroupId() {
      this.isShowWeChatNameConfirm = true;
    },
    async modifyGroupInfo() {
      // if(this.reportType===null||this.reportType.length===0){
      //   this.reportType=["日报"]
      // }
      // let fineParam = 0;
      // if (this.amountOfPunish !== '不罚款') {
      //   fineParam = Number(this.amountOfPunish.slice(0, -1));
      // }
      // console.log('fineParam')
      // console.log(fineParam)
      // const result = await group.postUpdateGroupInfo(
      //   {
      //     detail: {
      //       adminList: this.groupPresent.detail.adminList,
      //       fine: fineParam,
      //       // groupName: this.groupName,
      //       // minLength: this.minLength,
      //       needConfirm: this.needConfirm,
      //       // needReminder: this.needReminder,
      //       ownerId: this.groupPresent.detail.ownerId,
      //       // unfinishedInfoToAdmin: this.sendStatToAdmin,
      //       // unfinishedReminderToMember: this.sendWriteReminderToMember,
      //       // usedReportType:this.reportType,
      //     },
      //     groupId: this.groupPresent.groupId
      //   }
      // )
    },
    async settingReport() {
      if (this.isGroupAdmin || this.isGroupOwner) {
        const result = await report_reminder.getAllSettingByGroupId(
          this.groupPresent.groupId
        );
        console.log("各种汇报类型", result);

        if (result.code === 1) {
          if (result.data.length === 0) {
            await this.createGroupSetting();
          } else {
            this.reportType = this.getReportType(result.data);
            console.log("this.reportType");
            console.log(this.reportType);
            this.reportEnable = result.data[0].detail.enable;
            this.needReminder = result.data[0].detail.needReminder;
            this.minLength = result.data[0].detail.minLength;
            this.period = result.data[0].detail.period;
            this.sendStatToAdmin = result.data[0].detail.sendStatToAdmin;
            this.sendStatToAdminDate =
              result.data[0].detail.sendStatToAdminDate;
            this.sendWriteReminderToMember =
              result.data[0].detail.sendWriteReminderToMember;
            this.sendWriteReminderToMemberDate =
              result.data[0].detail.sendWriteReminderToMemberDate;

            this.reportsSetting = result.data;
          }
        }
      }
    },
    async createGroupSetting() {
      const result = await report_reminder.postCreateReportSetting({
        enable: this.reportEnable,
        needReminder: this.needReminder,
        groupId: this.groupPresent.groupId,
        minLength: this.minLength,
        period: this.period,
        sendStatToAdmin: this.sendStatToAdmin,
        sendStatToAdminDate: this.sendStatToAdminDate,
        sendWriteReminderToMember: this.sendWriteReminderToMember,
        sendWriteReminderToMemberDate: this.sendWriteReminderToMemberDate,
        type: this.reportType,
      });
      //Mo-ni：此处为了对用户透明创建，提示框内容设置为“修改”相关的
      // if(result.code===1){
      //   if(this.reportType!=='日报'){
      //     this.showAlert('设置成功')
      //     setTimeout(this.closeTip,1500)
      //   }
      // }else if(result.code===0){
      //   this.showAlert('设置失败，请稍后再试')
      // }
    },
    async updateGroupSetting() {
      const result = await report_reminder.postUpdateReportSetting({
        enable: this.reportEnable,
        needReminder: this.needReminder,
        groupId: this.groupPresent.groupId,
        minLength: this.minLength,
        period: this.period,
        sendStatToAdmin: this.sendStatToAdmin,
        sendStatToAdminDate: this.sendStatToAdminDate,
        sendWriteReminderToMember: this.sendWriteReminderToMember,
        sendWriteReminderToMemberDate: this.sendWriteReminderToMemberDate,
        type: this.reportType,
      });
      if (result.code === 1) {
        this.showAlert("设置成功");
        setTimeout(this.closeTip, 1500);
      } else if (result.code === 0) {
        this.createGroupSetting();
      }
    },
    async saveModify() {
      if (this.reportType === "月报") {
        this.sendWriteReminderToMemberDate = this.tempSendWriteReminderToMemberDate.toString();
        this.sendStatToAdminDate = this.tempSendStatToAdminDate.toString();
      }
      this.updateGroupSetting();
      let fineParam = 0;
      if (this.amountOfPunish !== "不罚款") {
        fineParam = Number(this.amountOfPunish.slice(0, -1));
      }
      const result = await group.postUpdateGroupInfo({
        detail: {
          adminList: this.groupPresent.detail.adminList,
          groupName: this.groupName,
          fine: fineParam,
          needConfirm: this.needConfirm,
          ownerId: this.groupPresent.detail.ownerId,
          weChatGroupName: this.weChatGroupName,
        },
        groupId: this.groupPresent.groupId,
      });
    },
    async getGroupSetting(type) {
      console.log("我要设置" + type);
      // if (type === '月报') {
      //   this.sendWriteReminderToMemberDate = ''
      //   this.sendStatToAdminDate = ''
      // }
      const result = await report_reminder.getSingleSettingByGroupId(
        this.groupPresent.groupId,
        type
      );
      if (result.code === 1) {
        this.reportType = result.data.detail.type;
        this.reportEnable = result.data.detail.enable;
        this.needReminder = result.data.detail.needReminder;
        this.minLength = result.data.detail.minLength;
        this.period = result.data.detail.period;
        this.sendStatToAdmin = result.data.detail.sendStatToAdmin;
        this.sendWriteReminderToMember =
          result.data.detail.sendWriteReminderToMember;
        if (result.data.detail.type === "月报") {
          this.tempSendStatToAdminDate = Number(
            result.data.detail.sendStatToAdminDate
          );
          this.tempSendWriteReminderToMemberDate = Number(
            result.data.detail.sendWriteReminderToMemberDate
          );
        } else {
          this.sendStatToAdminDate = result.data.detail.sendStatToAdminDate;
          this.sendWriteReminderToMemberDate =
            result.data.detail.sendWriteReminderToMemberDate;
        }
      } else if (result.code === 0 && result.message === "null") {
        this.createGroupSetting();
      }
    },
    searchResultFun() {
      this.searchResult = [];
      for (let i = 0; i < this.groupMembers.length; i++) {
        const s = this.groupMembers[i].detail.name;

        if (s.match(this.searchCondition)) {
          this.searchResult.push(this.groupMembers[i]);
        }
      }
      if (this.searchResult.length) {
      }
      this.searchResult.sort(compareByPinyin("detail name"));
      return this.searchResult;
    },
    showMoreMembers() {
      let box = document.getElementById("allMembers");
      if (this.moreMemberFlag) {
        box.scrollTop = 0;
        box.className = "limit_height";
        this.memberTips = "查看更多群成员 ▾ ";
      } else {
        box.className = "more_height";
        this.memberTips = "收起 ▴ ";
      }
      this.moreMemberFlag = !this.moreMemberFlag;
    },
    //获取本月的天数
    // daysOfMonthFun () {
    //   const date = new Date()
    //   let contDays = new Date(date.getFullYear(), date.getMonth() + 1, 0)
    //   // const contDays = new Date(2020, 5, 0)
    //   // console.log('本月的天数',contDays.getDate())
    //   this.daysOfMonth = contDays.getDate()
    // }
    //判断该群的汇报类型设置
    getReportType(item) {
      let arr = [0, 0, 0, 0];
      let temp;
      item.forEach((element) => {
        if (element.detail.type === "日报") {
          arr[0] = element;
        }
        if (element.detail.type === "周报") {
          arr[1] = element;
        }
        if (element.detail.type === "月报") {
          arr[2] = element;
        }
        if (element.detail.type === "年报") {
          arr[3] = element;
        }
      });
      try {
        arr.forEach((element) => {
          if (element !== 0 && element.detail.enable === true) {
            temp = element.detail.type;
            throw new error("终止foreach");
          }
        });
      } catch (e) {}
      return temp ? temp : arr[0].detail.type;
    },
  },
};
</script>
<style scoped>
.demo1-item {
  border: 1px solid #ececec;
  border-bottom: 1px solid green;
  padding: 5px 15px;
}

.demo1-item-selected {
  border: 1.5px solid green;
  border-bottom: 1px solid #ececec;
}

.mainbBg {
  height: calc(100% - 47px);
  /* height: 600px;
  overflow: scroll; */
  background: rgb(229, 229, 229);
}

.ul_box {
  list-style: none;
  margin-top: 30px;
  background-color: #fff;
  padding: 5px 20px;
  border: #b0c4de solid 1px;
  margin-bottom: -20px;
}

.list_item {
  margin: 0 5px;
  padding: 10px 5px;
  display: inline-flex;
}

.search_item {
  border: #213b4f dashed 1px;
  color: #213b4f;
  letter-spacing: 1px;
  font-size: 15px;
}

.manager_avatar {
  border: 1px solid #ddd;
}

.manager .userInf:first-child .manager_avatar {
  border: 1px solid #f4a460;
}

.manager .manager_avatar {
  border: 1px solid #6495ed;
}

.limit_height {
  max-height: 330px;
  overflow: hidden;
}

.more_height {
  max-height: 500px;
  overflow: auto;
}
</style>
